package com.zzw.bridge.system.service.impl;

import com.zzw.bridge.common.entitys.sys.SysUserEntity;
import com.zzw.bridge.security.user.UserDetail;
import com.zzw.bridge.system.convert.SysUserConvert;
import com.zzw.bridge.system.dao.SysRoleDao;
import com.zzw.bridge.system.enums.UserStatusEnum;
import com.zzw.bridge.system.service.SysMenuService;
import com.zzw.bridge.system.service.SysUserDetailsService;
import lombok.AllArgsConstructor;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;


@Service
@AllArgsConstructor
public class SysUserDetailsServiceImpl implements SysUserDetailsService {
	private final SysMenuService sysMenuService;
	private final SysRoleDao sysRoleDao;

	@Override
	public UserDetails getUserDetails (SysUserEntity userEntity) {
		// 转换成UserDetail对象
		UserDetail userDetail = SysUserConvert.INSTANCE.convertDetail(userEntity);

		// 账号不可用
		if (userEntity.getStatus() == UserStatusEnum.DISABLE.getValue()) {
			userDetail.setEnabled(false);
		}

		// 数据权限范围
		userDetail.setDataScopeList(null);

		// 用户权限列表
		//Set<String> authoritySet = sysMenuService.getUserAuthority(userDetail);
		userDetail.setAuthoritySet(new HashSet<>());

		return userDetail;
	}

}
